<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="12">
            <a-form-model-item label="档案大类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="docBigCategory">
              <j-dict-select-category :disabled=formDisabled v-model="model.docBigCategory" placeholder="请选择档案大类" parentCode="A04" :async="true" removeCode="A04A06,A04A05,A04A04,A04A03" @input="modifyCategory"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="档案小类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="docSmallCategory">
              <j-dict-select-category :disabled="formDisabled || !model.docBigCategory" v-model="model.docSmallCategory" placeholder="请选择档案小类" :parentCode="model.docBigCategory" :async="true"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所属公司" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="company">
              <select-Company-input   :disabled=formDisabled v-model="model.company" ></select-Company-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="档案所属团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamId">
             <select-team-input  :multi="false" :tdlx="3" :disabled=formDisabled v-model="model.teamId"  queryType="all" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="密级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="classification">
              <j-dict-select-tag  :disabled=formDisabled type="list" v-model="model.classification" dictCode="secrecy_level" placeholder="请选择密级" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="档案编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billNo">
              <a-input :disabled=formDisabled v-model="model.billNo" :max-length="36"  placeholder="请输入档案编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所属年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="year">
              <a-input :disabled=formDisabled v-model="model.year" :max-length="36"  placeholder="请输入所属年度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所属月份" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="month">
              <a-input :disabled=formDisabled v-model="model.month" :max-length="36"  placeholder="请输入所属月份"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="凭证号范围" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="voucherNumberRange">
              <a-input :disabled=formDisabled v-model="model.voucherNumberRange" :max-length="36"  placeholder="请输入凭证号范围"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="凭证数总册数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalNumber">
              <a-input-number :disabled=formDisabled :max="999999999" :min="0" :precision="0" v-model="model.totalNumber" placeholder="请输入凭证数总册数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交档人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="submitter">
              <select-user-by-dep   :multi="false" :disabled=formDisabled v-model="model.submitter" ></select-user-by-dep>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="监交人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supervisor">
              <select-user-by-dep   :multi="false" :disabled=formDisabled v-model="model.supervisor" ></select-user-by-dep>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="档案管理员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="archivist">
              <select-user-by-dep   :multi="false" :disabled=formDisabled v-model="model.archivist" ></select-user-by-dep>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="移交时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handoverTime">
              <j-date :disabled=formDisabled placeholder="请选择移交时间" v-model="model.handoverTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="闭合时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="closingTime">
              <j-date :disabled=formDisabled placeholder="请选择闭合时间" v-model="model.closingTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="档案室位置" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="docAddress">
              <a-input :disabled=formDisabled v-model="model.docAddress" :max-length="36"  placeholder="请输入档案室位置"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import JDictSelectCategory from '@/components/dict/JDictSelectCategory.vue'
  import moment from 'moment'
  import { mapGetters } from 'vuex'

  export default {
    name: 'ErpOaDocBaseInfoForm',
    components: {
      SelectUserByDep,
      SelectTeamInput,
      SelectCompanyInput,
      JDictSelectCategory
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/api/erp/oa/doc/erpOaDocBaseInfo/add",
          edit: "/api/erp/oa/doc/erpOaDocBaseInfo/edit",
          queryById: "/api/erp/oa/doc/erpOaDocBaseInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      modifyCategory(data){
        if(data){
          if(this.model.docSmallCategory){
            this.$set(this.model,"docSmallCategory",null);
          }
        }
      },
      ...mapGetters(['userInfo']),
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
                that.$emit('unButtonDisable');
              }
            }).catch((error)=>{
               that.$emit('unButtonDisable');
             }).finally(() => {
               that.confirmLoading = false;
             })
          }else {
           that.$emit('unButtonDisable');
          }

        })
      },
    }
  }
</script>
